home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000012_icon-group-sender _Mon Jul 10 07:46:06 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
5KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id HAA19920
for icon-group-addresses; Mon, 10 Jul 2000 07:44:44 -0700 (MST)
Message-Id: <200007101444.HAA19920@baskerville.CS.Arizona.EDU>
Date: Fri, 07 Jul 2000 20:50:58 -0700
From: Steve Wampler <sbw@tapestry.tucson.az.us>
X-Accept-Language: en
To: icon-group@optima.CS.Arizona.EDU
Subject: Friday puzzle...
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Content-Length: 4363
This is a multi-part message in MIME format.
--------------F23570175734CDBF613A10C4
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Every so often I've posed a programming problem here for Iconites to
work on. Here's another one, but this time I'm providing an
initial solution and the challenge is to find a faster solution
(the solution attached here is pretty slow...)
My son David asked me today a question about genetics: "If blood type O
is a recessive gene, then why does it dominate in the population?"
(~46% of the population is either O positive or O negative).
Well, I don't have an answer, so attached is a program to simulate
a population w.r.t a genetic trait (in this case, blood type). The
program is patterned (uh, loosely) after a real population - there
are humans, couples, births, and deaths, after a fashion.
Interestingly enough, starting with a population that is ~25% O
(the program combines positive and negative into the types), the
percentage is around 22% after 116 generations (which is as far as
the program has gotten while I'm typing this).
Anyway, can you find a faster way to simulate the population across
generations?
I'd also appreciate a correct answer to David's question that both
he and I can understand!
---
Steve Wampler {sbw@tapestry.tucson.az.us}
The gods that smiled upon your birth are laughing now. -- fortune cookie
--------------F23570175734CDBF613A10C4
Content-Type: text/plain; charset=us-ascii;
name="blood.icn"
Content-Disposition: inline;
filename="blood.icn"
Content-Transfer-Encoding: 7bit
#
# Simulate the gene pool w.r.t. blood types
#
global btypes # Genetic trait is blood type
record human(gene1, gene2) # A human has two blood type genes
record couple(p1, p2) # Takes two to tango
procedure main(args)
# introduce some randomess from one run to the next
write("Random seed: ",randSeed := &clock)
&random := map("HhMmSs","Hh:Mm:Ss", randSeed)
btypes := "ON" # simplify things "O" and "Not O"
nHumans := 10000 # small population
pool := createGenePool(nHumans)
analyzePool(pool)
every generation := 1 to 1000 do { # run for a lot of generations
pool := alterPool(pool)
if (generation % 1) == 0 then { # display every so often
write("Generation ",generation)
analyzePool(pool, "\t")
}
}
end
#
# Create the initial population
#
procedure createGenePool(size)
pool := set()
every 1 to size do insert(pool, newHuman())
return pool
end
#
# Create a new human, about 1 in 4 will be O blood type
#
procedure newHuman()
static initOdds
initial initOdds := repl("O",50) || repl("N",50)
return human(?initOdds, ?initOdds) # random genes
end
#
# See how the population is doing
#
procedure analyzePool(pool, prefix)
/prefix := ""
nO := nN := 0
every person := !pool do {
if (person.gene1 == "O") & (person.gene2 == "O") then
nO +:= 1
else
nN +:= 1
}
write(prefix, "Pool Size is: ",*pool)
write(prefix, "\tNumber O type: ",nO)
write(prefix, "\tNumber not O type: ",nN)
write(prefix, "\t% O type: ",real(nO)/*pool)
write()
end
#
# Put the population through a generation
#
procedure alterPool(pool)
static childProb # help in selecting number of children
initial childProb := [0,0,1,1,1,2,2,2,3,3,4]
newPool := set()
parents := []
every put(parents, marryOff(pool)) # wow, everyone marries!
# create the next generation
#
every pair := !parents do {
insert(newPool, pair.p1)
insert(newPool, pair.p2)
every 1 to ?childProb do {
# children get a gene from each parent
person := human(?(pair.p1), ?(pair.p2))
insert(newPool, person)
}
}
# now kill off enough to keep the population growth small
*
deaths := integer(*newPool * 0.46)
every 1 to deaths do {
delete(newPool, ?newPool)
}
return newPool
end
# Marry pairs of humans off (ok, so apparently the sex of each parent
# isn't important - must be New Hampshire?)
#
procedure marryOff(pool)
while *pool > 1 do {
delete(pool, p1 := ?pool)
delete(pool, p2 := ?pool)
suspend couple(p1, p2)
}
end
--------------F23570175734CDBF613A10C4--